<!DOCTYPE html>
<html>
    <head>
		<meta charset="utf-8">
		<title>技师列表</title>
		<link rel="stylesheet" href="__ADMIN_PATH__/component/pear/css/pear.css" />
		<style>
			.expand.pear-btn:hover {
				color: currentColor;
                background: none;
			}
			.expand.pear-btn {
				border: 1px solid rgba(255, 255, 255, 0)
			}
		</style>
	</head>
	<body class="pear-container">

		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">

						<div class="layui-inline">
							<label class="layui-form-label">真实姓名</label>
							<div class="layui-input-inline">
								<input type="text" name="title" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">昵称</label>
							<div class="layui-input-inline">
								<input type="text" name="nickname" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">手机号</label>
							<div class="layui-input-inline">
								<input type="text" name="mobile" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<div class="layui-input-inline">
								<select name="city" lay-verify="">
									<option value="">选择城市</option>
									{foreach name="city_list" item="value"}
									<option value="{$value['shi']}">{$value['company_name']}</option>
									{/foreach}
								</select>
							</div>
						</div>

						<div class="layui-inline" style="margin-left: 50px;">
							<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="search">
								<i class="layui-icon layui-icon-search"></i>
								查询
							</button>
							<button type="reset" class="pear-btn pear-btn-md">
								<i class="layui-icon layui-icon-refresh"></i>
								重置
							</button>
						</div>

					</div>
				</form>
			</div>
		</div>

		<div class="layui-card">
			<div class="layui-card-body">
				<table id="tableId" lay-filter="tableFilter"></table>
			</div>
		</div>

		<script src="__ADMIN_PATH__/component/layui/layui.js"></script>
		<script src="__ADMIN_PATH__/component/pear/pear.js"></script>
		<script>
			layui.use(['table', 'form', 'jquery','common', 'popup', 'loading'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;
				var popup = layui.popup;
				let loading = layui.loading;


				let articleTable = table.render({
					elem: '#tableId',
					method: "post",
					url: "{:url('techn/index')}",
					limit: 20,
					page: {
						curr: $('.layui-laypage-em').next().text(),
					},
					even: true,
					skin: 'line',
					toolbar: "#toolbarTpl",
					cols: [[
						{type: "checkbox"},
						{field: "id", title: "ID", width:200, sort: true, align: 'center'},
						{field: "real_name", title: "真实姓名", },
						{field: "nickname", title: "昵称", },
						{field: "mobile", title: "手机号", },
						{field: "work_img", title: "封面图片", templet:'#templetTpl'},
						{field: "sextitle", title: "性别"},
						{field: "age", title: "年龄"},
						{field: "workmsg", title: "状态"},
						{field: "lhtitle", title: "账号状态"},
						{field: "addr", title: "工作地区" },
						{title: "操作",  align: "center", toolbar: "#operationTpl"}
					]],
					done: function (res, curr, count) {
						console.log(res,curr,count)
					}
				});

				form.on('submit(search)', function(data) {
					articleTable.reload({
						where: data.field,
						page: {curr: 1}
					});
					return false;
				});

				table.on("toolbar(tableFilter)", function (obj) {
					switch (obj.event) {
						case "add":
							add();
						break;
					}
				});
				function add() {
					layer.open({
						type: 2,
						title: '新增',
						shade: 0.5,
						maxmin:true,
						area: [common.isModile() ? '100%' : '90%', common.isModile() ? '100%' : '90%'],
						content: "{:url('saveinfo')}"
					});
				}

				table.on("tool(tableFilter)", function (obj) {
					let data = obj.data;
					
					switch (obj.event) {
						case "update":
							update(data.save_url);
						break;

						case "del":
							del(data.id);
						break;
						
						case "cash":
							cash(data.id);
						break;
					}
				});
				function update(save_url) {
					layer.open({
						type: 2,
						title: '修改',
						shade: 0.5,
						maxmin:true,
						area: [common.isModile() ? '100%' : '90%', common.isModile() ? '100%' : '90%'],
						content: save_url
					});
				}


					console.log(url);

				//图片放大
				$(document).on('click', '.image-show', function () {
					var url = $(this).attr('src');
					//获取当前窗口的宽度
					var scr_width = $(window).width();
					if (scr_width > 1200) {
						 xp=600;   //大屏幕
					} else if (scr_width > 860) {
						 xp=500;   //中屏幕
					} else {
						 xp=300;   //超小屏幕
					}

					console.log(url);
					function getImageWidth(url, callback) {
						var img = new Image();
						img.src = url;
						if (img.complete) {
							callback(img.width, img.height)
						} else {
							img.onload = function () {
								callback(img.width, img.height)
							}
						}
					}
					getImageWidth(url, function (width, height) {
						if (height > xp) {
							var ratio = width / height;
							height = xp;
							width = height * ratio
						}
						if (width > xp) {
							var ratio = height / width;
							width = xp;
							height = width * ratio
						}
						layer.closeAll();
						layer.open({
							type: 1,
							closeBtn: 1,
							shade: false,
							title: false,
							shadeClose: false,
							area: ["auth", "auth"],
							content: '<img src="' + url + '" width="' + width + 'px" height="' + height + 'px">'
						})
					})
				});
				function del(id) {
					layer.confirm('确定要删除吗？', {
						icon: 3,
						title: '提示'
					}, function(index){
						$.ajax({
							url:"{:url('techn/delete')}",
							type:"POST",
							dataType:"JSON",
			                data:{
			                	id:id
			                },
			                beforeSend: function () {
			                	loading.Load(1, "");
			                },
			                complete: function () {
			                	loading.loadRemove();
			                	layer.close(index);
			                },
			                success:function(res)
			                {
			                	if(res.code == 0)
			                	{
			                		//正常业务
			                		popup.success(res.msg, function(){
			                			location.reload();
			                			layer.close(index); //再执行关闭
		                        	});
			                	}else
			                	{
			                		//业务异常
			                		popup.warning(res.msg);
			                	}
			                },
			                error:function()
			                {
			                	loading.loadRemove();
			                	layer.close(index);
			                	popup.failure('服务器错误');
			                }
			            });
			        });
			    }
			    
		    	function cash(id) {
				layer.confirm('确定要清除授权吗？', {
					icon: 3,
					title: '提示'
				}, function(index){
					$.ajax({
						url:"{:url('techn/cash')}",
						type:"POST",
						dataType:"JSON",
		                data:{
		                	id:id
		                },
		                beforeSend: function () {
		                	loading.Load(1, "");
		                },
		                complete: function () {
		                	loading.loadRemove();
		                	layer.close(index);
		                },
		                success:function(res)
		                {
		                	if(res.code == 0)
		                	{
		                		//正常业务
		                		popup.success(res.msg, function(){
		                			location.reload();
		                			layer.close(index); //再执行关闭
	                        	});
		                	}else
		                	{
		                		//业务异常
		                		popup.warning(res.msg);
		                	}
		                },
		                error:function()
		                {
		                	loading.loadRemove();
		                	layer.close(index);
		                	popup.failure('服务器错误');
		                }
		            });
		        });
			    }
			});
		</script>

		<!-- 头工具栏模板 -->
		<script type="text/html" id="toolbarTpl">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增
		    </button>
		</script>

		<!-- 行工具栏模板 -->
		<script type="text/html" id="operationTpl">
			<button  class="pear-btn pear-btn-primary pear-btn-sm" title="修改" lay-event="update">修改</button>
			<button class="pear-btn pear-btn-danger pear-btn-sm" title="删除" lay-event="del">删除</button>
		</script>

		<!--封面图片-->
		<script type="text/html" id="templetTpl">
			<img src="{{d.work_img}}" height="50" class="image-show" />
		</script>
		<style type="text/css">
		    .layui-table-cell{
		         height: auto!important;
		         white-space: normal;
		    }
		</style>
	</body>
</html>